/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.etcitem.action;

import com.lineage.server.model.L1CastleLocation;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.model.L1World;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.ItemExecutor;
import com.lineage.server.packetserver.S_ServerMessage;

/**
 * Class <code>TeleportsWeddingRing</code> 各种传送戒指 (结婚后可以使用的).<br>
 * 40901 - 结婚戒指(银)<br>
 * 40902 - 结婚戒指(金)<br>
 * 40903 - 结婚戒指(蓝宝石)<br>
 * 40904 - 结婚戒指(绿宝石)<br>
 * 40905 - 结婚戒指(红宝石)<br>
 * 40906 - 结婚戒指(钻石)<br>
 * 40907 - 西玛戒指<br>
 * 40908 - 欧林戒指<br>
 * 
 * @author jrwz
 * @version 2012-6-23下午12:52:11
 * @see com.lineage.server.model.item.etcitem.action
 * @since JDK1.7
 */
public final class TeleportsWeddingRing extends ItemExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static ItemExecutor get() {
        return new TeleportsWeddingRing();
    }

    /** 各种传送戒指 (结婚后可以使用的). */
    private TeleportsWeddingRing() {
    }

    @Override
    public void execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        L1PcInstance partner = null;
        boolean partner_stat = false;

        // 结婚中
        if (pc.getPartnerId() != 0) {
            partner = (L1PcInstance) L1World.getInstance().findObject(
                    pc.getPartnerId());
            if ((partner != null) && (partner.getPartnerId() != 0)
                    && (pc.getPartnerId() == partner.getId())
                    && (partner.getPartnerId() == pc.getId())) {
                partner_stat = true;
            }
        } else {
            pc.sendPackets(new S_ServerMessage(662)); // \f1你(你)目前未婚。
            return;
        }

        if (partner_stat) {
            // 任一城堡地区
            final boolean castle_area = L1CastleLocation.checkInAllWarArea(
                    partner.getX(), partner.getY(), partner.getMapId());
            if (((partner.getMapId() == 0) || (partner.getMapId() == 4) || (partner
                    .getMapId() == 304)) && (!castle_area)) {
                L1Teleport.teleport(pc, partner.getX(), partner.getY(),
                        partner.getMapId(), 5, true);
            } else {
                pc.sendPackets(new S_ServerMessage(547)); // \f1你的情人在你无法传送前往的地区。
            }
        } else {
            pc.sendPackets(new S_ServerMessage(546)); // \f1你的情人目前不在线上。
        }
    }
}
